{% extends "nav.html" %}
{% block little %}存储光交综合管理系统系统-存储信息{% endblock %}
{% block content %}
    <!-- Main Content -->
    <div class="container-fluid">
        <div class="side-body">
            <div class="page-title">
                <span class="title">存储信息查看</span>
                <div class="description">网服所有存储信息查看</div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="card-title">
                                <div class="title">存储列表</div>
                            </div>
                        </div>
                        <div class="card-body">
                            <table class="datatable table table-striped" id= "datatab_server" cellspacing="0" width="100%">
                                <thead>
                                <tr>
                                    <th>选择</th>
                                    <th>厂商</th>
                                    <th>型号</th>
                                    <th>sn</th>
                                    <th>机房位置</th>
                                    <th>管理IP</th>
                                    <th>裸容量(T)</th>
                                    <th>use(GB)</th>
                                    <th>avail(GB)</th>
                                    <th>total(GB)</th>
                                    <th>存储位置</th>
                                    <th>更新时间</th>
                                    {% if perms.STMAP %}
                                        <th>操作</th>
                                    {% endif %}
                                </tr>
                                </thead>
                                <tfoot>
                                <tr>
                                    <th>选择</th>
                                    <th>厂商</th>
                                    <th>型号</th>
                                    <th>sn</th>
                                    <th>机房位置</th>
                                    <th>管理IP</th>
                                    <th>裸容量(T)</th>
                                    <th>use(GB)</th>
                                    <th>avail(GB)</th>
                                    <th>total(GB)</th>

                                    <th>存储位置</th>
                                    <th>更新时间</th>
                                    {% if perms.STMAP %}
                                        <th>操作</th>
                                    {% endif %}
                                </tr>
                                </tfoot>
                                <tbody>
                                {% for i in data %}
                                    <tr aid="{{ i.id }}">
                                        <th><div class="checkbox"><input type="checkbox" name="{{ i.id }}" id="storage_select"></div></th>
                                        <td>{{ i.ST_prodname }}</td>
                                        <td><a href="{% url "storagemessages" i.id %}" target="_blank">{{ i.ST_prodect }}</a></td>
                                        <td><a href="{% url "storagemessages" i.id %}" target="_blank">{{ i.ST_sn }}</a></td>
                                        <td>{{ i.STjifang_adress }}</td>
                                        <td>{{ i.ST_ip }}</td>
                                        <td>{{ i.ST_totalrawcap }}</td>
                                        <td>{{ i.ST_usecap }}</td>
                                        <td>{{ i.ST_availcap }}</td>
                                        <td>{{ i.ST_totalcap }}</td>
                                        <td>{{ i.ST_position }}</td>
                                        <td>{{ i.ST_updatetime|date:"Y M d" }}</td>
                                        {#                                        <td><a name = "{{ i.id }}" type="botton" id="storage_update"class="btn btn-default  btn-xs" href="{% url "" i.id %}" target="_blank" role="button" style="margin: -5px" data-container="body" data-toggle="popover" data-placement="left" data-content="{{ i.doment_set.all.first.dotime}}">更 新</a></td>#}
                                        {#                                        <td><a name = "{{ i.id }}" type="botton" id="storage_update" class="btn btn-default  btn-xs"  role="button" style="margin: -5px" data-container="body" data-toggle="popover" data-placement="left" data-content="{{ i.doment_set.all.first.dotime}}">更 新</a></td>#}
                                        {% if perms.STMAP %}
                                            <td><a type="button" nid="{{ i.id }}" class="btn btn-info btn-xs st_sel_update" style="margin: 0px 0px;top: 0px;" >更  新</a>
                                                <a type="button" nid="{{ i.id }}" class="btn btn-danger btn-xs st_sel_delete" style="margin: 0px 0px;top: 0px;" >清  除</a>
                                            </td>
                                        {% endif %}
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                            {% if perms.STMAP %}
                                <div>
{#                                    <a type="button" class="btn btn-primary" id="storage_update">全部更新</a>#}
                                    <a type="button" class="btn btn-primary" id="storage_num_update">容量计算</a>
{#                                    <a type="button" class="btn btn-danger" id="storage_delete">清空所有存储数据</a>#}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <div class="modal fade" tabindex="-1" role="dialog" id="san_update">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">更新存储新</h4>
                </div>
                <div class="modal-body">
                    <p id="storge_err">添加任务中,请等待&hellip;</p>
                    <div class="progress">
                        <div id="storage_jindutiao" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default st_close" data-dismiss="modal" id="storage_close">关闭</button>
                    {#                    <button type="button" class="btn btn-primary">Save changes</button>#}
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <script>
        $(".st_sel_delete").click(function () {
            $('#san_update').modal({backdrop: 'static', keyboard: false},'toggle')
            $("#storage_close").hide();
            var nid = $(this).attr("nid")
            $.ajax({
                url: "{% url "storage_one_delete_ajax" %}",
                type: 'POST',
                data:{"id":nid},
                success: function(data){
                    var obj = JSON.parse(data);
                    if(obj.status){
                        $("#storge_err").text("清除成功");
                        $("#storage_close").show();
                        $("#storage_jindutiao").hide();
                    }else{
                        $("#storge_err").text("清除失败：" + obj.error);
                        $("storage_jindutiao").hide();
                        $("#storage_close").show();
                    };
                }

            });
        });
        $(".st_sel_update").click(function () {
            $('#san_update').modal({backdrop: 'static', keyboard: false},'toggle')
            $("#storage_close").hide();
            $("#storage_jindutiao").show();
            var nid = $(this).attr("nid")
            $.ajax({
                url: "{% url "storage_one_update_ajax" %}",
                type: 'POST',
                data:{"id":nid},
                success: function(data){
                    var obj = JSON.parse(data);
                    if(obj.status){
                        $("#storge_err").text("任务添加成功");
                        $("#storage_close").show();
                        $("#storage_jindutiao").hide();
                    }else{
                        $("#storge_err").text("更新失败：" + obj.error);
                        $("storage_jindutiao").hide();
                        $("#storage_close").show();
                    };
                }
            });
        });
        $("#storage_update").click(function () {
            $('#san_update').modal({backdrop: 'static', keyboard: false},'toggle')
            $("#storage_close").hide();
            $.ajax({
                url: "{% url "storage_update_ajax" %}",
                type: 'POST',
                data:"ok",
                success: function(data){
                    var obj = JSON.parse(data);
                    if(obj.status){
                        $("#storge_err").text("任务添加成功");
                        $("#storage_close").show();
                        $("#storage_jindutiao").hide();
                    }else{
                        $("#storge_err").text("更新失败：" + obj.error);
                        $("storage_jindutiao").hide();
                        $("#storage_close").show();
                    };
                }
            });
        });

        $("#storage_num_update").click(function () {
            $('#san_update').modal({backdrop: 'static', keyboard: false},'toggle')
            $("#storage_close").hide();
            $.ajax({
                url: "{% url "storage_num_update_ajax" %}",
                type: 'POST',
                data:"ok",
                success: function(data){
                    var obj = JSON.parse(data);
                    if(obj.status){
                        $("#storge_err").text("更新成功");
                        $("#storage_close").show();
                        $("#storage_jindutiao").hide();
                    }else{
                        $("#storge_err").text("更新失败：" + obj.error);
                        $("storage_jindutiao").hide();
                        $("#storage_close").show();
                    };
                }
            });
        });
    </script>
{% endblock %}
